%%
    addpath includes
    clf
    h1=subplot(2,1,1);
    temp=struct2cell(event);
    temp=temp([1:7 9],1,:);
    temp=cell2mat(temp);
    % Colors
        %   123456789
        cl='rbggkrkbr';
        ml=' so*+d.^v';
    % Legend labels
    oknolabel={'T','S1-G1','S1-G2','S1-G3','S1-Z','S2-G1','S2-G2','S2-G3','S2-Z'};
    for okno=2:9
        temper=[];
        temprms=[];
        for i=1:length(temp)
            ytemp=baddays(:,shiftdim(temp(5,1,i)));
            if interp1(baddays(ytemp>0,1),ytemp(ytemp>0),shiftdim(temp(2,1,i)))>0.9 && ...
                    shiftdim(temp(5,1,i))==okno
                temper=[temper; shiftdim(temp(2,1,i)),shiftdim(temp(3,1,i)),shiftdim(temp(4,1,i))];
                temprms=[temprms; shiftdim(temp(8,1,i))];
            end
        end
        if size(temper)>0
            subplot(2,1,1)
            h=errorbar(temper(:,1),temper(:,2),temper(:,3),...
                    [ml(okno) cl(okno)],...
                    'MarkerSize',5);
                errorbar_tick(h,2000);
                hold on
                subplot(2,1,2)
            h=plot(temper(:,1),temprms,...
                    ['-' cl(okno)],...
                    'MarkerSize',5);
%                 errorbar_tick(h,2000);
                hold on
        end
    end
    h(1)=subplot(2,1,1);
    hold off
    grid on
    legend(oknolabel(2:end))
    ylabel('Frequency [Hz]');
    h(2)=subplot(2,1,2);
    hold off
    grid on
    ylabel('RMS [counts/s]')
    xlabel('MJD')
    linkaxes(h,'x')
    %%
    subplot(2,2,[2 4])
    clf
    evnum=2;
%     h=errorbar([event(evnum).profile(:,1)' event(evnum).profile(:,1)'],[event(evnum).profile(:,2)' event(evnum).profile(:,2)'],'.')
   
%                 errorbar_tick(h,2000);
                hold on
    stairs([event(evnum).profile(:,1)' event(evnum).profile(:,1)'])
    grid on
    %%
%     h2=subplot(2,1,2)
%     plot(baddays(:,1),baddays(:,2))
%     linkaxes([h1 h2],'x')
% %%
% MJDlist=mjuliandate(datelist)+anint/2;
% RMSlist=MJDlist*NaN;
% profhist=zeros(40,length(MJDlist))*NaN;
% okno=6;
% for i=1:length(MJDlist)
%     for j=1:length(event)
%         if event(j).MJD==MJDlist(i) && event(j).okno==okno
%             temp=event(j).profile(:,1);
%             RMSlist(i)=std(temp);
%             temp=temp./std(temp);
%             temp=circshift(temp,-find(temp==min(temp)));
%             profhist(:,i)=[temp' temp']';
%         end
%     end
% end
% %
% % surf((0:39)/20,MJDlist,profhist')
% % view(135,29)
% % h=[];
% % h(1)=subplot(2,1,1);
% % imagesc(MJDlist,(0:39)/20,profhist)
% % h(2)=subplot(2,1,2);
% % plot(MJDlist,RMSlist)
% % grid on
% % linkaxes(h,'x')